package com.efuture.chapterthree

/* @Description: 内置函数takeif的使用
 * @Auther: zhaoshanshan
 * @Date: 2022/03/06/2:26 下午
 */
fun main() {
    println(checkPermission2("zhaoshanshan","12456"))
}

fun checkPermission(userName:String,pwd:String):Boolean{
    return userName=="zhaoshanshan"&&pwd=="123456"
}
fun checkPermission2(userName:String,pwd:String):String{
    //userName.takeIf 当该内置函数的结果为true 则返回userName 否则返回null 通常结合空合并操作符来使用
    return userName.takeIf {checkPermission(userName,pwd)}?:"权限不够"
}